home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / msgq160s.arc / EIDBASE.C < prev    next >
C/C++ Source or Header  |  1991-10-26  |  2KB  |  88 lines

  1. /*
  2.  * EIDBASE.C - MsgLink message base functions
  3.  *
  4.  * This file is not used by Msged/Q
  5.  */
  6.  
  7. #include <string.h>
  8. #include <fcntl.h>
  9. #include <io.h>
  10.  
  11. #include "msglink.h"
  12.  
  13. static char *expandbbs(char *fname);
  14. static int openfile(char *fname);
  15.  
  16. /*
  17.  * Return a pointer to a static expanded path
  18.  */
  19.  
  20. static char *expandbbs(char *fname)
  21. {
  22.   static char name[PATHLEN];
  23.  
  24.   strcpy(name, bbspath);
  25.   strcat(name, fname);
  26.   return(name);
  27. } /* expandbbs */
  28.  
  29. static int openfile(char *fname)
  30. {
  31.   return(open(expandbbs(fname), O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE));
  32. } /* openfile */
  33.  
  34. /*
  35.  * Open all the message base files
  36.  * Returns TRUE if ok
  37.  */
  38.  
  39. BOOLEAN openmsgbase()
  40. {
  41.   struct stat st;
  42.   BYTE i;
  43.  
  44.   for (i = f_first;  i <= f_last;  i++)        /* open all files */
  45.     if ((F[i] = openfile(FN[i])) == -1)
  46.       return(FALSE);
  47.  
  48.   memset(&msginfo, 0, sizeof(msginfo));        /* clear the record */
  49.   read(F[f_info], (char *)&msginfo, sizeof(msginfo));    /* if just created - read nothing */
  50.  
  51.   memset(&st, 0, sizeof(st));
  52.   fstat(F[f_hdr], &st);
  53.  
  54.   filemsgs = st.st_size/sizeof(MSGHEADER);    /* number of messages */
  55.   if ((msgidx = calloc(filemsgs+1,sizeof(IDXRECORD))) == NULL)
  56.     return FALSE;
  57.   read(F[f_idx], (char *)msgidx, (size_t)filemsgs*sizeof(IDXRECORD));
  58.  
  59.   memset(lastread, 0, sizeof(lastread));
  60.   if (lseek(F[f_last], (long)usernum * sizeof(lastread), SEEK_SET) == -1) {
  61.     fprintf(stderr,"\nNo lastread info exists for '%s' (%d)",username,usernum);
  62.     getch();
  63.     return FALSE;
  64.   } /* if */
  65.   read(F[f_last], (char *)lastread, sizeof(lastread));
  66.  
  67.   memset(current, 0, sizeof(current));
  68.   read(F[f_cur], (char *)current, sizeof(current));
  69.  
  70.   for (i = 0;  i < BLIM;  i++) {
  71.     int first = firstmsg(i+1);
  72.     int last  = lastmsg(i+1);
  73.  
  74.     if (lastread[i] > last)
  75.       lastread[i] = last;
  76.     else if (lastread[i] < first)
  77.       lastread[i] = first;
  78.  
  79.     if (current[i] > lastread[i])
  80.       current[i] = lastread[i];
  81.     else if (current[i] < first)
  82.       current[i] = first;
  83.   } /* for */
  84.  
  85.   return TRUE;
  86. } /* openmsgbase */
  87.  
  88.